package com.canaan.business.controller.pc.agv;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import com.canaan.business.domain.agv.AgvTaskConfig;
import com.canaan.business.domain.agv.UpdateAgvTaskConfigParam;
import com.canaan.business.service.agv.IAgvTaskConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.domain.R;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务配置Controller
 *
 * @author
 * @date 2023-03-02
 */
@Api(tags = "任务配置")
@RestController
@RequestMapping("/wcs/agvTaskConfig")
public class AgvTaskConfigController extends BaseController {
    @Resource
    private IAgvTaskConfigService agvTaskConfigService;

    /**
     * 查询任务配置列表
     */
    @ApiOperation(value = "查询任务配置列表")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgvTaskConfig agvTaskConfig) {
        startPage();
        List<AgvTaskConfig> list = agvTaskConfigService.selectAgvTaskConfigList(agvTaskConfig);
        return getDataTable(list);
    }

    /**
     * 导出任务配置列表
     */
    @ApiOperation(value = "导出任务配置列表")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:export')")
    @Log(title = "任务配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgvTaskConfig agvTaskConfig) {
        List<AgvTaskConfig> list = agvTaskConfigService.selectAgvTaskConfigList(agvTaskConfig);
        ExcelUtil<AgvTaskConfig> util = new ExcelUtil<AgvTaskConfig>(AgvTaskConfig.class);
        util.exportExcel(response, list, "任务配置数据");
    }

    /**
     * 获取任务配置详细信息
     */
    @ApiOperation(value = "获取任务配置详细信息")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(agvTaskConfigService.selectAgvTaskConfigById(id));
    }

    /**
     * 新增任务配置
     */
    @ApiOperation(value = "新增任务配置")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:add')")
    @Log(title = "任务配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgvTaskConfig agvTaskConfig) {
        return toAjax(agvTaskConfigService.insertAgvTaskConfig(agvTaskConfig));
    }

    /**
     * 修改任务配置
     */
    @ApiOperation(value = "修改任务配置")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:edit')")
    @Log(title = "任务配置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult edit(@RequestBody AgvTaskConfig agvTaskConfig) {
        return toAjax(agvTaskConfigService.updateAgvTaskConfig(agvTaskConfig));
    }

    /**
     * 删除任务配置
     */
    @ApiOperation(value = "删除任务配置")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskConfig:remove')")
    @Log(title = "任务配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(agvTaskConfigService.deleteAgvTaskConfigByIds(ids));
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有", notes = "查询所有")
    public R all() {
        return R.ok(this.agvTaskConfigService.selectAgvTaskConfigList(new AgvTaskConfig()));
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑", notes = "编辑")
    public R update(@RequestBody UpdateAgvTaskConfigParam param) {
        this.agvTaskConfigService.updateAgvTaskConfig(param);
        return R.ok();
    }
}
